package cn.IT.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.IT.dao.IUserDAO;
import cn.IT.domain.User;

@Repository
@SuppressWarnings("all")
public class UserDAO extends BaseDAO<User> implements IUserDAO{
	@Override
	public User getUserByNameAndPassword(User u) {
		List<User> list = find("from User u where u.userName='"+u.getUserName()+ "'and u.password='" +u.getPassword()+"'");
		if(!list.isEmpty()){
			return (User)list.get(0);
		}
		return null;
	}
	@Override
	public List<User> getAllUserExceptSelf(User u) {
		List<User> list = find("from User u where u.userId<>'"+u.getUserId()+"'");
		System.out.println(list.size());
		if(!list.isEmpty()){
			return list;
		}
		return null;
	}
	@Override
	public List<User> getAllApproversExceptSelf(User u) {
		List<User> list = find("from User u where u.userId<>'"+u.getUserId()+"' and u.professionalTitle = 'Manager'");
		System.out.println(list.size());
		if(!list.isEmpty()){
			return list;
		}
		return null;
	}
	@Override
	public List<User> getAllUserOrderByContribute() {
		List<User> list = find("from User u order by u.contributionCount desc");
		System.out.println(list.size());
		if(!list.isEmpty()){
			return list;
		}
		return null;
	}
	
}
